<template>
  <div class="box">
    <Levelpassword>
      <div class="flex">
        <el-form :inline="true" :model="where" label-position="top">
          <el-form-item>
            <el-select v-model="where.checkout_id" @change="billsModel.page(1)">
              <el-option
                v-for="(item, index) in checkout"
                :key="index"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div style="width: 300px"><Daterange @date="date => {where.time = date; billsModel.page(1)}" /></div>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="billsModel.getList()" style="width: 100%;">
        <el-table-column :label="plugin.lang('bills.start_end')" width="180">
          <template #default="scope">
            <template  v-if="scope.row.start_time > 0">
              <el-tag>{{ time.format(scope.row.start_time) }}</el-tag><br>
            </template>
            <el-tag type="success" v-if="scope.row.end_time">
              {{ time.format(scope.row.end_time) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column :label="plugin.lang('bills.checkout_name')" prop="checkout_name" width="200" />
        <el-table-column :label="plugin.lang('bills.account_name')" prop="account_name" />
        <el-table-column :label="plugin.lang('bills.start_money')" align="center" >
          <template #default="scope">
            {{ money(scope.row.start_money) }}
          </template>
        </el-table-column>
        <el-table-column :label="plugin.lang('bills.cash_money')" align="center" >
          <template #default="scope">
            {{ money(scope.row.cash_money) }}
          </template>
        </el-table-column>
        <el-table-column :label="plugin.lang('bills.pay_money')" align="center" >
          <template #default="scope">
            {{ money(scope.row.pay_money) }}
          </template>
        </el-table-column>
        <el-table-column :label="plugin.lang('bills.with_money')" align="center" >
          <template #default="scope">
            {{ money(scope.row.with_money) }}
          </template>
        </el-table-column>
        <el-table-column :label="plugin.lang('bills.total')" align="center" >
          <template #default="scope">
            <el-link type="primary" href="javascript:;">{{ money(scope.row.total) }}</el-link>
          </template>
        </el-table-column>
        <el-table-column :label="plugin.lang('bills.sub_money')" align="center" >
          <template #default="scope">
            <el-tag :type="scope.row.sub_money < 0 ? 'error' : 'success'" effect="plain">{{ money(scope.row.sub_money) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :label="plugin.lang('bills.time')" width="150">
          <template #default="scope">
            {{ time.format(scope.row.created_at) }}
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          @current-change="billsModel.page"
          v-model:currentPage="where.page"
          :page-size="where.page_size"
          layout="total, prev, pager, next, jumper"
          :total="where.page_total"
          background>
        </el-pagination>
      </div>
    </Levelpassword>
  </div>
</template>
<script>
import app from '@/app'
import billsModel from '../../model/bills'
import checkoutModel from '@/model/account/checkout'
import accountModel from '@/model/account'
import Daterange from '@/components/daterange'
import Levelpassword from '@/components/levelpassword'

export default {
  components: {
    Daterange,
    Levelpassword
  },
  setup() {
    // 条件 
    const where = billsModel.data

    // 默认当前收银台
    where.value.checkout_id = accountModel.getCheckout().id
    where.value.time = []

    // 收银台列表 
    const checkout = checkoutModel.list

    // 加载列表
    billsModel.get()

    return {
      lang: app.lang,
      plugin: app.plugin.index,
      time: app.time,
      money: app.money,
      billsModel,
      where,
      checkout,
    }
  }
}
</script>